package org.crazyit.activiti_d4._6_DeploymentQuery;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.repository.Deployment;

import java.util.List;

public class DeploymentQuery {

    public static void main(String[] args) {

        //1. 创建流程引擎
        ProcessEngine engine = ProcessEngines.getDefaultProcessEngine();

        //2. 得到流程存储服务实例
        RepositoryService repositoryService = engine.getRepositoryService();

        //3. 写入5 条Deployment 数据
        Deployment depA = repositoryService.createDeployment()
                .addString("a1", "a1")
                .addString("a2", "a2")
                .addString("a3", "a3")
                .name("a")
                .deploy();
        Deployment depB = repositoryService.createDeployment()
                .addString("b1", "b1")
                .addString("b2", "b2")
                .addString("b3", "b3")
                .name("b")
                .deploy();
        Deployment depC = repositoryService.createDeployment()
                .addString("c1", "c1")
                .addString("c2", "c2")
                .addString("c3", "c3")
                .name("c")
                .deploy();
        Deployment depD = repositoryService.createDeployment()
                .addString("d1", "d1")
                .addString("d2", "d2")
                .addString("d3", "d3")
                .name("d")
                .deploy();
        Deployment depE = repositoryService.createDeployment()
                .addString("e1", "e1")
                .addString("e2", "e2")
                .addString("e3", "e3")
                .name("e")
                .deploy();

        //4. deploymentId 方法
        Deployment depAQuery = repositoryService.createDeploymentQuery().deploymentId(depA.getId()).singleResult();
        System.out.println("根据id 查询:" + depAQuery.getName());

        //5. deploymentName 方法
        Deployment depBQuery = repositoryService.createDeploymentQuery().deploymentName(depB.getName()).singleResult();
        System.out.println("根据名称为b 查询:" + depBQuery.getName());

        //6. deploymentNameLike 方法
        List<Deployment> depCQuery = repositoryService.createDeploymentQuery().deploymentNameLike("%c%").list();
        System.out.println("根据名称为c 进行模糊查询, 结果数量为:" + depCQuery.size());

    }

}
